/*     */ package com.zimbra.qa.unittest.prov.soap;
/*     */ 
/*     */ import com.google.common.collect.Lists;
/*     */ import com.google.common.collect.Maps;
/*     */ import com.google.common.collect.Sets;
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.ZAttrProvisioning.AccountStatus;
/*     */ import com.zimbra.common.auth.ZAuthToken;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AccountConstants;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.HeaderConstants;
/*     */ import com.zimbra.common.soap.SoapFaultException;
/*     */ import com.zimbra.common.soap.SoapHttpTransport;
/*     */ import com.zimbra.common.soap.SoapHttpTransport.HttpDebugListener;
/*     */ import com.zimbra.common.soap.SoapProtocol;
/*     */ import com.zimbra.common.soap.SoapTransport;
/*     */ import com.zimbra.common.util.ByteUtil;
/*     */ import com.zimbra.common.util.ZimbraHttpConnectionManager;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.qa.unittest.TestUtil;
/*     */ import com.zimbra.qa.unittest.prov.Verify;
/*     */ import com.zimbra.soap.account.message.GetInfoRequest;
/*     */ import com.zimbra.soap.account.message.GetInfoResponse;
/*     */ import com.zimbra.soap.account.type.Attr;
/*     */ import com.zimbra.soap.account.type.AuthToken;
/*     */ import com.zimbra.soap.admin.message.ClearCookieRequest;
/*     */ import com.zimbra.soap.admin.message.ClearCookieResponse;
/*     */ import com.zimbra.soap.admin.message.NoOpRequest;
/*     */ import com.zimbra.soap.admin.message.NoOpResponse;
/*     */ import com.zimbra.soap.admin.type.CookieSpec;
/*     */ import com.zimbra.soap.type.AccountBy;
/*     */ import com.zimbra.soap.type.AccountSelector;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStreamReader;
/*     */ import java.io.PrintStream;
/*     */ import java.text.ParseException;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Collections;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import java.util.Set;
/*     */ import org.apache.commons.httpclient.Cookie;
/*     */ import org.apache.commons.httpclient.Header;
/*     */ import org.apache.commons.httpclient.HttpClient;
/*     */ import org.apache.commons.httpclient.HttpState;
/*     */ import org.apache.commons.httpclient.URI;
/*     */ import org.apache.commons.httpclient.methods.PostMethod;
/*     */ import org.apache.commons.httpclient.methods.StringRequestEntity;
/*     */ import org.apache.commons.httpclient.params.HttpMethodParams;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestAuth
/*     */   extends SoapTest
/*     */ {
/*     */   private static SoapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  91 */     provUtil = new SoapProvTestUtil();
/*  92 */     prov = provUtil.getProv();
/*  93 */     domain = provUtil.createDomain(baseDomainName());
/*     */   }
/*     */   
/*     */ 
/*     */   @AfterClass
/*  98 */   public static void cleanup() throws Exception { Cleanup.deleteAll(new String[] { baseDomainName() }); }
/*     */   
/*     */   private String getAuthToken(String acctName, boolean isAdmin) throws Exception {
/*     */     SoapTransport transport;
/*     */     SoapTransport transport;
/* 103 */     if (isAdmin) {
/* 104 */       transport = authAdmin(acctName);
/*     */     } else {
/* 106 */       transport = authUser(acctName);
/*     */     }
/* 108 */     return transport.getAuthToken().getValue();
/*     */   }
/*     */   
/*     */ 
/*     */   private static class AuthTokenInCookieTransport
/*     */     extends SoapHttpTransport
/*     */   {
/*     */     private boolean isAdmin;
/*     */     private String authTokenForCookie;
/*     */     private boolean voidAuthTokenOnExpired;
/*     */     
/*     */     private AuthTokenInCookieTransport(String authTokenForCookie, boolean isAdmin)
/*     */     {
/* 121 */       this(authTokenForCookie, isAdmin, false, null);
/*     */     }
/*     */     
/*     */     private AuthTokenInCookieTransport(String authTokenForCookie, boolean isAdmin, boolean voidAuthTokenOnExpired, SoapDebugListener debugListener)
/*     */     {
/* 126 */       super();
/* 127 */       this.isAdmin = isAdmin;
/* 128 */       this.authTokenForCookie = authTokenForCookie;
/* 129 */       this.voidAuthTokenOnExpired = voidAuthTokenOnExpired;
/* 130 */       setHttpDebugListener(debugListener == null ? new SoapDebugListener(SoapDebugListener.Level.ALL) : debugListener);
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */     public Element invoke(Element document, boolean raw, boolean noSession, String requestedAccountId, String changeToken, String tokenType)
/*     */       throws ServiceException, IOException
/*     */     {
/* 138 */       String uri = this.isAdmin ? TestUtil.getAdminSoapUrl() : TestUtil.getSoapUrl();
/* 139 */       HttpClient httpClient = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient();
/*     */       
/* 141 */       ZAuthToken zAuthToken = new ZAuthToken(this.authTokenForCookie);
/* 142 */       Map<String, String> cookieMap = zAuthToken.cookieMap(this.isAdmin);
/*     */       
/* 144 */       PostMethod method = new PostMethod(uri + "unittest");
/*     */       try {
/* 146 */         Element envelope = generateSoapMessage(document, raw, noSession, requestedAccountId, changeToken, tokenType);
/*     */         
/*     */ 
/* 149 */         if (this.voidAuthTokenOnExpired) {
/* 150 */           Element eCtxt = SoapProtocol.Soap12.getHeader(envelope, HeaderConstants.CONTEXT);
/* 151 */           Element eAuthTokenControl = eCtxt.addElement("authTokenControl");
/* 152 */           eAuthTokenControl.addAttribute("voidOnExpired", true);
/*     */         }
/* 154 */         String soapMessage = SoapProtocol.toString(envelope, getPrettyPrint());
/* 155 */         method.setRequestEntity(new StringRequestEntity(soapMessage, null, "UTF-8"));
/*     */         
/* 157 */         HttpState state = null;
/* 158 */         if (cookieMap != null) {
/* 159 */           for (Map.Entry<String, String> ck : cookieMap.entrySet()) {
/* 160 */             if (state == null) {
/* 161 */               state = new HttpState();
/*     */             }
/* 163 */             state.addCookie(new Cookie(method.getURI().getHost(), (String)ck.getKey(), (String)ck.getValue(), "/", null, false));
/*     */           }
/*     */         }
/*     */         
/* 167 */         HttpMethodParams params = method.getParams();
/* 168 */         params.setCookiePolicy(state == null ? "ignoreCookies" : "compatibility");
/*     */         
/* 170 */         if (getHttpDebugListener() != null) {
/* 171 */           getHttpDebugListener().sendSoapMessage(method, envelope, state);
/*     */         }
/*     */         
/* 174 */         int respCode = httpClient.executeMethod(null, method, state);
/*     */         
/* 176 */         InputStreamReader reader = new InputStreamReader(method.getResponseBodyAsStream(), SoapProtocol.getCharset());
/*     */         
/* 178 */         String responseStr = ByteUtil.getContent(reader, (int)method.getResponseContentLength(), false);
/*     */         
/* 180 */         Element soapResp = parseSoapResponse(responseStr, false);
/*     */         
/* 182 */         if (getHttpDebugListener() != null) {
/* 183 */           getHttpDebugListener().receiveSoapMessage(method, soapResp);
/*     */         }
/*     */         
/* 186 */         return soapResp;
/*     */       } finally {
/* 188 */         method.releaseConnection();
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void soapByCookie() throws Exception {
/* 195 */     boolean isAdmin = false;
/*     */     
/* 197 */     String USER_NAME = TestUtil.getAddress("user1");
/* 198 */     String authToken = getAuthToken(USER_NAME, isAdmin);
/*     */     
/* 200 */     Element req = Element.create(SoapProtocol.Soap12, AccountConstants.GET_INFO_REQUEST);
/*     */     
/* 202 */     SoapTransport transport = new AuthTokenInCookieTransport(authToken, isAdmin, null);
/* 203 */     Element resp = transport.invoke(req);
/* 204 */     Element eName = resp.getElement("name");
/* 205 */     String value = eName.getText();
/* 206 */     Assert.assertEquals(USER_NAME, value);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void soapByCookieAdmin() throws Exception {
/* 211 */     boolean isAdmin = true;
/*     */     
/* 213 */     String USER_NAME = TestUtil.getAddress("admin");
/* 214 */     String authToken = getAuthToken(USER_NAME, isAdmin);
/*     */     
/* 216 */     Element req = Element.create(SoapProtocol.Soap12, AdminConstants.GET_CONFIG_REQUEST);
/* 217 */     req.addElement("a").addAttribute("n", "cn");
/*     */     
/* 219 */     SoapTransport transport = new AuthTokenInCookieTransport(authToken, isAdmin, null);
/* 220 */     Element resp = transport.invoke(req);
/* 221 */     Element eA = resp.getElement("a");
/* 222 */     String value = eA.getText();
/* 223 */     Assert.assertEquals("config", value);
/*     */   }
/*     */   
/*     */ 
/*     */   private static class VerifyCookieExpireListener
/*     */     extends SoapDebugListener
/*     */   {
/*     */     private String cookieToVerify;
/*     */     
/*     */     private VerifyCookieExpireListener(String cookieToVerify)
/*     */     {
/* 234 */       super();
/* 235 */       this.cookieToVerify = cookieToVerify;
/*     */     }
/*     */     
/*     */     public void receiveSoapMessage(PostMethod postMethod, Element envelope)
/*     */     {
/* 240 */       super.receiveSoapMessage(postMethod, envelope);
/*     */       
/*     */ 
/* 243 */       Map<String, String> cookieAttrMap = Maps.newHashMap();
/*     */       
/* 245 */       Header[] headers = postMethod.getResponseHeaders();
/* 246 */       for (Header header : headers) {
/* 247 */         System.out.println(header.toString().trim());
/*     */         
/* 249 */         if (header.getName().equals("Set-Cookie")) {
/* 250 */           cookieAttrMap.clear();
/*     */           
/*     */ 
/* 253 */           String value = header.getValue();
/* 254 */           String[] attrs = value.split(";");
/* 255 */           for (String attr : attrs) {
/* 256 */             String[] kv = attr.split("=");
/* 257 */             if (kv.length == 2) {
/* 258 */               cookieAttrMap.put(kv[0], kv[1]);
/* 259 */             } else if (kv.length == 1) {
/* 260 */               cookieAttrMap.put(kv[0], "is-present");
/*     */             }
/*     */           }
/*     */           
/* 264 */           if (cookieAttrMap.get(this.cookieToVerify) != null) {
/*     */             break;
/*     */           }
/*     */           
/*     */ 
/* 269 */           cookieAttrMap.clear();
/*     */         }
/*     */       }
/*     */       
/*     */ 
/*     */ 
/* 275 */       Assert.assertNotNull(cookieAttrMap.get(this.cookieToVerify));
/* 276 */       String expires = (String)cookieAttrMap.get("Expires");
/*     */       try {
/* 278 */         Date date = new SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z").parse(expires);
/* 279 */         int hour = date.getHours();
/* 280 */         int hourNow = new Date(System.currentTimeMillis()).getHours();
/* 281 */         int expectedExpireHour = hourNow + 1;
/* 282 */         if (expectedExpireHour >= 24) {
/* 283 */           expectedExpireHour -= 24;
/*     */         }
/* 285 */         Assert.assertEquals(expectedExpireHour, hour);
/*     */       } catch (ParseException e) {
/* 287 */         Assert.fail();
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void authTokenCookieMaxAge() throws Exception {
/* 294 */     String authTokenLifetime = "1h";
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 299 */     Account admin = provUtil.createGlobalAdmin(genAcctNameLocalPart("admin"), domain);
/*     */     
/*     */ 
/* 302 */     admin.setAdminAuthTokenLifetime(authTokenLifetime);
/*     */     
/* 304 */     SoapHttpTransport transportAdmin = new SoapHttpTransport(TestUtil.getAdminSoapUrl());
/* 305 */     transportAdmin.setHttpDebugListener(new VerifyCookieExpireListener("ZM_ADMIN_AUTH_TOKEN", null));
/*     */     
/* 307 */     com.zimbra.soap.admin.message.AuthRequest reqAdmin = new com.zimbra.soap.admin.message.AuthRequest(admin.getName(), "test123");
/*     */     
/* 309 */     reqAdmin.setPersistAuthTokenCookie(Boolean.TRUE);
/* 310 */     com.zimbra.soap.admin.message.AuthResponse respAdmin = (com.zimbra.soap.admin.message.AuthResponse)invokeJaxb(transportAdmin, reqAdmin);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 315 */     Account acct = provUtil.createAccount(genAcctNameLocalPart("user"), domain);
/*     */     
/*     */ 
/* 318 */     acct.setAuthTokenLifetime(authTokenLifetime);
/*     */     
/* 320 */     SoapHttpTransport transportAcct = new SoapHttpTransport(TestUtil.getSoapUrl());
/* 321 */     transportAcct.setHttpDebugListener(new VerifyCookieExpireListener("ZM_AUTH_TOKEN", null));
/*     */     
/* 323 */     com.zimbra.soap.account.message.AuthRequest reqAcct = new com.zimbra.soap.account.message.AuthRequest(AccountSelector.fromName(acct.getName()), "test123");
/*     */     
/* 325 */     reqAcct.setPersistAuthTokenCookie(Boolean.TRUE);
/* 326 */     com.zimbra.soap.account.message.AuthResponse respAcct = (com.zimbra.soap.account.message.AuthResponse)invokeJaxb(transportAcct, reqAcct);
/*     */     
/* 328 */     provUtil.deleteAccount(admin);
/* 329 */     provUtil.deleteAccount(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void clearCookie() throws Exception {
/* 334 */     int authTokenLifetimeMSecs = 2000;
/* 335 */     int waitMSecs = authTokenLifetimeMSecs + 1000;
/*     */     
/* 337 */     Account acct = provUtil.createGlobalAdmin(genAcctNameLocalPart(), domain);
/*     */     
/*     */ 
/* 340 */     acct.setAdminAuthTokenLifetime(String.valueOf(authTokenLifetimeMSecs) + "ms");
/*     */     
/*     */ 
/* 343 */     SoapTransport transport = authAdmin(acct.getName());
/*     */     
/*     */ 
/* 346 */     Thread.sleep(waitMSecs);
/*     */     
/*     */ 
/* 349 */     boolean caughtAuthExpired = false;
/*     */     try {
/* 351 */       NoOpRequest noOpReq = new NoOpRequest();
/* 352 */       noOpResp = (NoOpResponse)invokeJaxb(transport, noOpReq);
/*     */     } catch (ServiceException e) { NoOpResponse noOpResp;
/* 354 */       if ("service.AUTH_EXPIRED".equals(e.getCode())) {
/* 355 */         caughtAuthExpired = true;
/*     */       }
/*     */     }
/* 358 */     Assert.assertTrue(caughtAuthExpired);
/*     */     
/* 360 */     List<CookieSpec> cookiesToClear = Lists.newArrayList(new CookieSpec[] { new CookieSpec("ZM_ADMIN_AUTH_TOKEN") });
/* 361 */     ClearCookieRequest req = new ClearCookieRequest(cookiesToClear);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 367 */     caughtAuthExpired = false;
/*     */     try {
/* 369 */       invokeJaxb(transport, req);
/*     */     } catch (ServiceException e) {
/* 371 */       if ("service.AUTH_EXPIRED".equals(e.getCode())) {
/* 372 */         caughtAuthExpired = true;
/*     */       }
/*     */     }
/* 375 */     Assert.assertTrue(caughtAuthExpired);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 381 */     String authToken = transport.getAuthToken().getValue();
/* 382 */     SoapTransport authTokenInCookieTransport = new AuthTokenInCookieTransport(authToken, true, null);
/* 383 */     caughtAuthExpired = false;
/*     */     try {
/* 385 */       invokeJaxb(authTokenInCookieTransport, req);
/*     */     } catch (ServiceException e) {
/* 387 */       if ("service.AUTH_EXPIRED".equals(e.getCode())) {
/* 388 */         caughtAuthExpired = true;
/*     */       }
/*     */     }
/* 391 */     Assert.assertTrue(caughtAuthExpired);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 399 */     SoapDebugListener verifyCookieClearedListener = new SoapDebugListener(SoapDebugListener.Level.ALL)
/*     */     {
/*     */       public void receiveSoapMessage(PostMethod postMethod, Element envelope) {
/* 402 */         super.receiveSoapMessage(postMethod, envelope);
/*     */         
/*     */ 
/* 405 */         Header[] headers = postMethod.getResponseHeaders();
/* 406 */         boolean cookieCleared = false;
/* 407 */         for (Header header : headers) {
/* 408 */           if (header.toString().trim().equals("Set-Cookie: ZM_ADMIN_AUTH_TOKEN=;Path=/;Expires=Thu, 01-Jan-1970 00:00:00 GMT"))
/*     */           {
/* 410 */             cookieCleared = true;
/*     */           }
/*     */         }
/*     */         
/* 414 */         Assert.assertTrue(cookieCleared);
/*     */       }
/*     */       
/*     */ 
/* 418 */     };
/* 419 */     authTokenInCookieTransport = new AuthTokenInCookieTransport(authToken, true, true, verifyCookieClearedListener, null);
/*     */     
/*     */ 
/*     */ 
/* 423 */     ClearCookieResponse resp = (ClearCookieResponse)invokeJaxb(authTokenInCookieTransport, req);
/*     */     
/* 425 */     provUtil.deleteAccount(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void accountStatusMaintenance() throws Exception {
/* 430 */     Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain, Collections.singletonMap("zimbraAccountStatus", ZAttrProvisioning.AccountStatus.maintenance.name()));
/*     */     
/*     */ 
/*     */ 
/* 434 */     String errorCode = null;
/*     */     try {
/* 436 */       transport = authUser(acct.getName());
/*     */     } catch (SoapFaultException e) { SoapTransport transport;
/* 438 */       errorCode = e.getCode();
/*     */     }
/* 440 */     Assert.assertEquals("account.MAINTENANCE_MODE", errorCode);
/*     */     
/* 442 */     provUtil.deleteAccount(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void accountStatusMaintenanceAfterAuth() throws Exception {
/* 447 */     Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
/*     */     
/* 449 */     SoapTransport transport = authUser(acct.getName());
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 454 */     prov.modifyAccountStatus(acct, ZAttrProvisioning.AccountStatus.maintenance.name());
/*     */     
/* 456 */     GetInfoRequest req = new GetInfoRequest();
/*     */     
/* 458 */     String errorCode = null;
/*     */     try {
/* 460 */       resp = (GetInfoResponse)invokeJaxb(transport, req);
/*     */     } catch (SoapFaultException e) { GetInfoResponse resp;
/* 462 */       errorCode = e.getCode();
/*     */     }
/* 464 */     Assert.assertEquals("service.AUTH_EXPIRED", errorCode);
/*     */     
/* 466 */     provUtil.deleteAccount(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void attrsReturnedInAuthResponse() throws Exception {
/* 471 */     String ATTR_NAME = "zimbraFeatureExternalFeedbackEnabled";
/* 472 */     String ATTR_VALUE = "TRUE";
/*     */     
/* 474 */     Map<String, Object> attrs = Maps.newHashMap();
/* 475 */     attrs.put(ATTR_NAME, ATTR_VALUE);
/*     */     
/* 477 */     Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain, attrs);
/*     */     
/* 479 */     SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
/* 480 */     transport.setHttpDebugListener(new SoapDebugListener());
/*     */     
/* 482 */     AccountSelector acctSel = new AccountSelector(AccountBy.name, acct.getName());
/*     */     
/*     */ 
/* 485 */     com.zimbra.soap.account.message.AuthRequest req = new com.zimbra.soap.account.message.AuthRequest(acctSel, "test123");
/* 486 */     req.addAttr(ATTR_NAME);
/* 487 */     com.zimbra.soap.account.message.AuthResponse resp = (com.zimbra.soap.account.message.AuthResponse)invokeJaxb(transport, req);
/*     */     
/* 489 */     Set<String> result = Sets.newHashSet();
/* 490 */     for (Attr attr : resp.getAttrs()) {
/* 491 */       String attrName = attr.getName();
/* 492 */       String attrValue = attr.getValue();
/*     */       
/* 494 */       result.add(Verify.makeResultStr(new Object[] { attrName, attrValue }));
/*     */     }
/* 496 */     Verify.verifyEquals(Sets.newHashSet(new String[] { Verify.makeResultStr(new Object[] { ATTR_NAME, ATTR_VALUE }) }), result);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 501 */     String authTokenStr = resp.getAuthToken();
/* 502 */     AuthToken authToken = new AuthToken(authTokenStr, Boolean.FALSE);
/* 503 */     req = new com.zimbra.soap.account.message.AuthRequest();
/* 504 */     req.setAuthToken(authToken);
/* 505 */     req.addAttr(ATTR_NAME);
/*     */     
/* 507 */     transport = new SoapHttpTransport(TestUtil.getSoapUrl());
/* 508 */     transport.setHttpDebugListener(new SoapDebugListener());
/*     */     
/* 510 */     resp = (com.zimbra.soap.account.message.AuthResponse)invokeJaxb(transport, req);
/*     */     
/* 512 */     result = Sets.newHashSet();
/* 513 */     for (Attr attr : resp.getAttrs()) {
/* 514 */       String attrName = attr.getName();
/* 515 */       String attrValue = attr.getValue();
/*     */       
/* 517 */       result.add(Verify.makeResultStr(new Object[] { attrName, attrValue }));
/*     */     }
/* 519 */     Verify.verifyEquals(Sets.newHashSet(new String[] { Verify.makeResultStr(new Object[] { ATTR_NAME, ATTR_VALUE }) }), result);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void OAuth() throws Exception {
/* 524 */     Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
/*     */     
/* 526 */     SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
/*     */     
/* 528 */     Element eAuthReq = Element.create(transport.getRequestProtocol(), AccountConstants.AUTH_REQUEST);
/*     */     
/*     */ 
/*     */ 
/* 532 */     Element eAuthToken = eAuthReq.addElement("authToken");
/* 533 */     eAuthToken.addAttribute("type", "oauth");
/*     */     
/* 535 */     String accessToken = "whatever";
/* 536 */     Element eAccessToken = eAuthToken.addElement("a");
/* 537 */     eAccessToken.addAttribute("n", "access_token");
/* 538 */     eAccessToken.setText(accessToken);
/*     */     
/*     */ 
/* 541 */     Element eAcct = eAuthReq.addElement("account");
/* 542 */     eAcct.addAttribute("by", Key.AccountBy.name.name());
/* 543 */     eAcct.setText(acct.getName());
/*     */     
/* 545 */     Element eResp = transport.invoke(eAuthReq);
/*     */     
/* 547 */     Element eAuthTokenResp = eResp.getElement("authToken");
/* 548 */     String authToken = eAuthTokenResp.getText();
/* 549 */     Assert.assertNotNull(authToken);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/soap/TestAuth.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */